package tlog

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

type macZapLogInit struct {
}

func (ms *macZapLogInit) loginit(config *logConf) (zap.AtomicLevel, *zap.Logger, error) {
	var (
		zapconfig zap.Config
		llevel    zap.AtomicLevel
		lzaplog   *zap.Logger
		err       error
	)

	zapconfig = zap.NewProductionConfig()
	zapconfig.Encoding = config.encodeing
	zapconfig.DisableStacktrace = true
	zapconfig.EncoderConfig.TimeKey = "timestamp"                   //"@timestamp"
	zapconfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder //epochSecondTimeEncoder //RFC3339TimeEncoder
	lzaplog, err = zapconfig.Build()
	llevel = zapconfig.Level

	var levelInit = false
	if len(config.logLevel) > 0 {
		lerr := llevel.UnmarshalText([]byte(config.logLevel))
		levelInit = lerr == nil
	}
	if !levelInit {
		if config.testenv {
			llevel = zap.NewAtomicLevelAt(zap.DebugLevel)
		} else {
			llevel = zap.NewAtomicLevelAt(zap.InfoLevel)
		}
	}
	return llevel, lzaplog, err
}
